package by.bsu.fpmi.bbtp.impl;

import by.bsu.fpmi.bbtp.controllers.GoodController;
import by.bsu.fpmi.bbtp.dao.GoodDAO;
import by.bsu.fpmi.bbtp.entities.Good;
import by.bsu.fpmi.bbtp.entities.GoodHead;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.List;

@WebService(endpointInterface = "by.bsu.fpmi.bbtp.controllers.GoodController")
public class GoodControllerImpl implements GoodController {

    @Autowired
    private GoodDAO goodDao;

    @Override
    public List<GoodHead> getAllGoods(String sessionId) {
        return getHeads(goodDao.all());
    }

    @Override
    public Good getGood(String sessionId, long goodId) {
        return goodDao.find(goodId);
    }
    
    private List<GoodHead> getHeads(List<Good> goods) {
        List<GoodHead> heads = new ArrayList<GoodHead>();
        for (Good good : goods) {
            heads.add(good.getHead());
        }
        return heads;
    }
}
